home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / fulledit / fulledit.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  4.6 KB  |  225 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "work:romconf/doorheader.h"
  6. #define RIGHTARROW 2
  7. #define LEFTARROW 3
  8. #define UPARROW 4
  9. #define DOWNARROW 5
  10. #define gu getuserstring
  11. char cmd[100];
  12. char im[200][82];
  13. int x,y,line;
  14. void end();
  15. void showstat(int line,int x,int y);
  16. void InitArray();
  17. void SaveAs();
  18. void showarg(char *str[]);
  19. void makearg(char *str);
  20. void sr(char *str);
  21. void LoadForm(char *str);
  22. void Goto(int x,int y);
  23. int node;
  24. #define sm sendmessage
  25. #define cm sendchar
  26. #define pu putuserstring
  27. #define co ConOnly
  28. char *argment[50];
  29. int argcount=0;
  30. struct FORM
  31. {
  32.   short x,y;
  33. } Fm[100];
  34. int LastForm=0;
  35. int CurrForm=0;
  36. main(int argc,char *argv[])
  37. {
  38.   char hmd;
  39.   BOOL stop=FALSE;
  40.   int tline=0,i;
  41.   x=y=line=0;
  42.  
  43.   if(argc!=2)
  44.   {
  45.      printf("FullEdit v1.0 written by Joseph Hodge\n");
  46.      printf("This is an XIM for AmiExpress v2.0+\n");
  47.      printf("\n");
  48.      exit(0);
  49.   }
  50.   Register(argv[1][0]-'0');
  51.   node = argv[1][0]-'0';
  52.   pu(NULL,RAWARROW);
  53.   InitArray();
  54.   sm(" ",0);
  55.  
  56.   sm("FullEdit version 1.0  written by Joseph Hodge",1);
  57. sm("------------------------------------------------------------------------------",1);
  58.  
  59.   sm("1H",0);
  60.   sm("",0);
  61.  
  62. sm("------------------------------------------------------------------------------",1);
  63. sm("Press '/' at the begining of any line to exit editor.",1);
  64. sm("------------------------------------------------------------------------------",0);
  65.   co(" p",0);showstat(line,x,y); co(" p",0);
  66.   gu(cmd,BB_MAINLINE);
  67.   makearg(cmd);
  68.   
  69.   if(argcount==2)
  70.   {
  71.     LoadForm(argment[1]);
  72.   }
  73.   Goto(Fm[CurrForm].x+1,Fm[CurrForm].y); x=Fm[CurrForm].x;
  74.   y=Fm[CurrForm].y;
  75.   do
  76.   {
  77.      hmd=Fhotkey();
  78.      switch(hmd)
  79.      {
  80.        case LEFTARROW: x +=1; if(x>79) x=79; else sm("C",0); break;
  81.        case RIGHTARROW:x -=1; if(x<0) x=0; else sm("D",0); break;
  82.        case UPARROW: y -=1; if(y<0) y=0; else { sm("A",0); tline--; }break;
  83.        case DOWNARROW: y +=1; if(y>16) y=16; else{ sm("B",0); tline++;
  84.                       if(tline>line) line++;} break;
  85.        case 12:
  86.        case 13:
  87.                 CurrForm +=1; if(CurrForm>=LastForm) CurrForm=0;
  88.                 y=Fm[CurrForm].y; x=Fm[CurrForm].x; Goto(x,y);
  89.                 /*y +=1; x=0; if(y>16) y=16; else { tline++;if(tline>line)line++;}
  90.                */ break;
  91.        case '\b':
  92.             x = x-1; if(x<0) x=0; else sm("\b \b",0); break;
  93.        default: if(hmd=='/' && x==0) { stop=TRUE; break;} cm(hmd,0); im[y][x]=hmd; x +=1; if(x>79)x=79;
  94.              
  95.      }
  96.      co(" p",0);showstat(line,x,y); co(" p",0);
  97.   }while(!stop);
  98.   
  99.   SaveAs();
  100.   sm(" ",0);
  101.   sm("",1);
  102.   sm("Exiting FullEdit",1);
  103.   sm("",1);
  104.   ShutDown();
  105.   end();
  106. }
  107. void InitArray()
  108. {
  109.   register int i,j;
  110.   for(i=0;i<200;i++)
  111.   {
  112.     for(j=0;j<79;j++)
  113.      im[i][j]=' '; im[i][j]='\0';
  114.   }
  115. }
  116. void showstat(int line,int x,int y)
  117. {
  118.   char str[200];
  119. /*    sm("",0);
  120.     sm("H",0);
  121.  
  122.  
  123. sprintf(str,"--%3d--%2d--%2d--------------------------------------------------------------",line,x,y);
  124.     sm(str,1);
  125. */
  126.     sprintf(str,"%d;%dH",y+3,x+1);
  127.     sm(str,0);
  128. }
  129. void SaveAs()
  130. {
  131.   FILE *fi;
  132.   char FileName[80];
  133.   register int i;
  134.   gu(cmd,BB_LOCAL);
  135.   sprintf(FileName,"%sNode%d/Work/msg",cmd,node);
  136.   fi=fopen(FileName,"w");
  137.   if(fi==NULL)
  138.   {
  139.     sm("Error, cannot locate node(x)/work",1);
  140.     return;
  141.   }
  142.   i=0;
  143.   while(i<line)
  144.   {
  145.     fprintf(fi,"%s\n",im[i]);
  146.     i++;
  147.   }
  148.   fclose(fi);
  149. }
  150. void end()
  151. {
  152.   exit(0);
  153. }
  154. void showarg(char *str[])
  155. {
  156.   register int i=0;
  157.   while(str[i][0]!=NULL)
  158.   {
  159.     strcpy(cmd,str[i]);
  160.     sm(cmd,1);
  161.     i++;
  162.   }
  163. }
  164. void makearg(char *str)
  165. {
  166.   static int i=0;
  167.   static int j=0;
  168.   argcount=0;
  169. while(1)
  170. {
  171.   argment[j]=str+i; j++; argment[j]=NULL; argcount++;
  172.   if(*(str+i)=='\0') { argment[j]=NULL; return; }
  173.   while(*(str+i)>32)
  174.   {
  175.     i++;
  176.   }
  177.   if(*(str+i)=='\0') return;
  178.   *(str+i)='\0';i++;
  179.  }
  180. }
  181.  
  182. void LoadForm(char *str)
  183. {
  184.   FILE *fi;
  185.   char local[100];
  186.   register int i=0,j;
  187.   fi=fopen(str,"r");
  188.   if(fi==NULL) return;
  189.   while(fgets(cmd,80,fi)!=NULL && i<15)
  190.   {
  191.    
  192.     j=0; 
  193.     sprintf(local,"%d;%dH",i+3,1);
  194.     sm(local,0);
  195.     sr(cmd);
  196.     while(cmd[j]!='\0' && j<79)
  197.     {
  198.       im[i][j]=cmd[j]; if(cmd[j]=='[') { Fm[LastForm].x=j+1;
  199.                                          Fm[LastForm].y=i; LastForm++; }
  200.       j++;
  201.     }
  202.     sm(cmd,0);
  203.     i++; line++;
  204.   }
  205.   fclose(fi);
  206. }
  207.  
  208. void sr(char *str)
  209. {
  210.   register int i;
  211.   i=strlen(str)-1;
  212.   while(i>-1)
  213.   {
  214.     if(*(str+i)<=32) *(str+i)='\0'; else break;
  215.     i--;
  216.   }
  217. }
  218.  
  219. void Goto(int x,int y)
  220. {
  221.   char local[20];
  222.   sprintf(local,"%d;%dH",y+3,x);
  223.   sm(local,0);
  224. }
  225.